package com.os.meituan.controller.good;

import com.github.pagehelper.PageInfo;
import com.os.meituan.common.XJsonInfo;
import com.os.meituan.mapper.good.T_GOOD_TypeGoodMapper;
import com.os.meituan.model.pomodel.Shop.T_SHOP_Good;
import com.os.meituan.model.pomodel.Shop.T_SHOP_Imformation;
import com.os.meituan.model.vomodel.Shop.VO_SHOP_SearchForIndex;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(tags = "OA-GOOD-美团")
@RestController
@RequestMapping("/api/oa/fra/ord")
public class GoodController {

    @Resource
    private T_GOOD_TypeGoodMapper t_good_typeGoodMapper;

    @ApiOperation("查询所有有炒粉卖的店")
    @GetMapping("/getTypeGood")
    public XJsonInfo getList1(String str) {

        var list = t_good_typeGoodMapper.getTypeGood(str);

        var endlist = new ArrayList<VO_SHOP_SearchForIndex>();//不能直接new list  因为 list 是抽象类。返回endlist

        for (var bo : list) {
            var vo = new VO_SHOP_SearchForIndex();

            // 判断endlist里是否已经有当前店铺
            var flag = false; // 定义一个标记，作为是否找得到的初始值
            for (var endVO : endlist) {
                if (endVO.getShopInfo().getId().equals(bo.getGoodName())) {

                    // 如果有，则增加商品信息
                    var shopGood = new T_SHOP_Good();
                    shopGood.setName(bo.getGoodName());
                    endVO.getShopGoodList().add(shopGood);

                    flag = true;
                    break;
                }
            }

            // 如果没，则新增商店
            if (!flag) {
                var endVO = new VO_SHOP_SearchForIndex();

                var shopImfor = new T_SHOP_Imformation();
                shopImfor.setStoreName(bo.getShopName());
                endVO.setShopInfo(shopImfor);

                var shopGood = new T_SHOP_Good();
                shopGood.setName(bo.getGoodName());
                endVO.getShopGoodList().add(shopGood);


                endlist.add(endVO);
            }

        }

        PageInfo page = new PageInfo(endlist); //ERROR 这里的分页由于变更了查询的结果内容，所以这样写应该是错的
        return XJsonInfo.success().setPageData(page);
    }


    @GetMapping("/getTest")
    @ApiOperation("倒叙数组")
    public String test(String str) {


        char[] chars = str.toCharArray();
        int strIndex = 0;
        for (int i = 0; i < chars.length; i++) {
            if (!Character.isDigit(str.charAt(i))) {
                strIndex = i;
                System.out.println("字符串下标" + i);
                break;
            }
        }
        /* System.out.println(str.substring(strIndex,str.length()));*/
        return str.substring(strIndex, str.length());



     /*   String str2 = "";
        char[] a = x.toCharArray();//字符串转换为char数组
        for(int i=a.length-1;i>=0;i--){
            if(a[i] != '0') {
                str2 += a[i];//从最后一个字符开始往前拼接
            }

        }
     *//*   String result=str2.replaceAll("^(0+)", "");*//*
        return str2;*/
    }


}



